/*!
 * \file iptools_parse_mac.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    char *str_mac = (char *)"02:ea:12:56:66:77";
    int i_size = 0;
    unsigned char mac[APM_MAC_SIZE];
    unsigned char mac_real[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);
    memset(mac_real,'\0',APM_MAC_SIZE);

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);
    CU_ASSERT(memcmp(mac,mac_real,sizeof(mac)) == 0);

}

static void __case2(void)
{
    char *str_mac = (char *)"02:ea:12:56:66:77";
    int i_size = 3;
    unsigned char mac[3];
    unsigned char mac_real[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);
    memset(mac_real,'\0',APM_MAC_SIZE);

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);
    CU_ASSERT(memcmp(mac,mac_real,sizeof(mac)) == 0);

}

static void __case3(void)
{
    char *str_mac = (char *)"02-ea-12-56-66-77";
    int i_size = 6;
    unsigned char mac[APM_MAC_SIZE];
    unsigned char mac_real[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);
    memset(mac_real,'\0',APM_MAC_SIZE);

    mac_real[0] = 0x02;

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);
    CU_ASSERT(memcmp(mac,mac_real,sizeof(mac)) == 0);

}

static void __case4(void)
{
    char *str_mac = (char *)"gg";
    int i_size = 6;
    unsigned char mac[APM_MAC_SIZE];
    unsigned char mac_real[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);
    memset(mac_real,'\0',APM_MAC_SIZE);

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);
    CU_ASSERT(memcmp(mac,mac_real,sizeof(mac)) == 0);

}

static void __case5(void)
{
    char *str_mac = (char *)"02:ea:12:56:66:77";
    int i_size = 6;
    unsigned char mac[APM_MAC_SIZE];
    unsigned char mac_real[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);
    memset(mac_real,'\0',APM_MAC_SIZE);

    mac_real[0]= 0x02;
    mac_real[1]= 0xea;
    mac_real[2]= 0x12;
    mac_real[3]= 0x56;
    mac_real[4]= 0x66;
    mac_real[5]= 0x77;

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,1);
    CU_ASSERT(memcmp(mac,mac_real,sizeof(mac)) == 0);

}


static void __case6(void)
{
    char *str_mac = (char *)"02:ea:12:56:66:778";
    int i_size = 6;
    unsigned char mac[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);

}


static void __case7(void)
{
    char *str_mac = (char *)"02:ea:12:56:66:77:882";
    int i_size = 6;
    unsigned char mac[APM_MAC_SIZE];
    int i_ret = 0;

    memset(mac,'\0',APM_MAC_SIZE);

    i_ret = iptools_parse_mac(str_mac,mac,i_size);

    CU_ASSERT_EQUAL(i_ret,0);

}


int add_suite_iptools_parse_mac(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frsutl iptools_parse_mac()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);


    return FR_SUCC;
}
